<template>
	<view>
		<my-search></my-search>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in swiperList" :key='index'>
				<navigator class="swiper-item" :url="`/ok/goods_detail/goods_detail?goods_id=${item.goods_id}`">
					<image :src="item.image_src" mode=""></image>
				</navigator>
			</swiper-item>
		</swiper>
		<view class='nav-list'>
			<view class='nav-item' v-for="(item,index) in navList" :key='index' @click="goCate(item)">
				<image :src="item.image_src" mode=""></image>
			</view>
		</view>
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<image class="floor-item-title" :src="item.floor_title.image_src"></image>

				<view class="floor-img-box">
					<navigator class="left-img-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" mode=""></image>
					</navigator>
					<view class="right-img-box">
						<navigator class="right-img-item" v-for="(item2,index2) in item.product_list" :key="index2"
							v-if="index2 !== 0" :url="item2.url">
							<image class="right-item-img" :src="item2.image_src" mode=""></image>
						</navigator>
					</view>
				</view>
			</view>

		</view>
	</view>

</template>

<script>
	import {
		swiperdata,
		catitemsdata,
		floordata
	} from '@/api/home_request.js';
	export default {
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: [],
			};
		},
		methods: {
			async swipera() {
				const {
					data: res
				} = await swiperdata();
				// console.log(res);
				if (res.meta.status !== 200) {
					return uni.showToast({
						title: "数据请求失败",
						duration: 2000,
						icon: "none"

					})
				}
				this.swiperList = res.message;
			},
			async getcatitemsdata() {
				const {
					data: res
				} = await catitemsdata();
				// console.log(res);
				if (res.meta.status !== 200) {
					return uni.showToast({
						title: "数据请求失败",
						icon: "none"

					})
				}
				this.navList = res.message;
			},
			async getfloordata() {
				const {
					data: res
				} = await floordata();
				console.log(res);
				if (res.meta.status !== 200) return uni.$showMsg();
				res.message.forEach(floor => {
					floor.product_list.forEach(prod => {
						prod.url = '/ok/goods_list/goods_list?' + prod.navigator_url.split('?')[1];
					})
				})
				this.floorList = res.message;
			},
			goCate(item) {
				if (item.name === '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			}
		},

		onLoad() {
			this.swipera();
			this.getcatitemsdata();
			this.getfloordata()
		}

	}
</script>

<style lang="scss">
	swiper {
		height: 350rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 40rpx 0;

		.nav-item {
			width: 140rpx;
			height: 120rpx;

			image {
				width: 100%;
				height: 140%;
			}

		}
	}

	.floor-list {
		.floor-item {
			margin-left: 10rpx;
			margin-bottom: 10rpx;

			.floor-item-title {
				margin-top: 20px;
				width: 100%;
				height: 60rpx;
			}

			.floor-img-box {
				display: flex;
				height: 400rpx;

				.left-img-box {
					width: 33%;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.right-img-box {
					width: 66%;
					display: flex;
					flex-wrap: wrap;

					.right-img-item {
						width: 48%;

						.right-item-img {
							width: 100%;
							height: 100%;
						}
					}
				}
			}

		}
	}
</style>
